<template>
  <view>
    <view class="input-search">
    	<uni-easyinput prefixIcon="search"  trim="all" v-model="keyword" :styles="styles" :placeholderStyle="placeholderStyle"></uni-easyinput>
    	<button @click="search">搜索</button>
    </view>
	<uni-table ref="table" type="selection" :loading="loading" emptyText="暂无更多数据" filter-type="search"  @selection-change="selectionChange">
		<uni-tr>
			<uni-th class="th-class">
				<button class="close_btn" @click="toCheck">复核并同步</button>
			</uni-th>
		</uni-tr>
		<uni-tr v-for="(item, index) in card_arr" :key="index">
			<uni-td width="100%" align="left" class="td-class" >
				<div @click="selectes(item)" class="td_div">
					<view class="td_list" v-if="order_type!=14?true:false">
						<text class="label">源单编号</text>
						<text class="text">{{ item.source_code }}</text>
					</view>
					<view class="td_list">
						<text class="label">订单编号</text>
						<text class="text">{{ item.pcode }}</text>
					</view>
					<view class="td_list">
						<text class="label">日期</text>
						<text class="text">{{ item.createtime }}</text>
					</view>
					<view class="td_list">
						<text class="label">物料编码</text>
						<text class="text">{{ item.inv_number }}</text>
					</view>
					<view class="td_list">
						<text class="label">名称</text>
						<text class="text">{{ item.inv_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">规格</text>
						<text class="text">{{ item.inv_specification }}</text>
					</view>
					<view class="td_list">
						<text class="label">批号</text>
						<text class="text">{{ item.cBatch }}</text>
					</view>
					<view class="td_list">
						<text class="label">位置</text>
						<text class="text">{{ item.warehouse_name }} - {{ item.shelves_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">基本单位</text>
						<text class="text">{{ item.unit }}</text>
						<text class="label">常用单位</text>
						<text class="text">{{ item.store_unit }}</text>
					</view>
					<view class="td_list" v-if="order_type==14?true:false">
						<text class="label">目标仓库</text>
						<text class="text">{{ item.warehouse_change_name }}</text>
						<text class="label">目标库区</text>
						<text class="text">{{ item.shelves_change_name }}</text>
					</view>
					<view class="td_list">
						<text class="label">基本数量</text>
						<text class="text">{{ item.quantity }}</text>
						<text class="label">常用数量</text>
						<text class="text">{{ item.store_quantity }}</text>
					</view>
					<view class="td_list">
						<text class="label">复核状态</text>
						<text class="text font-red">{{ item.status==0?'待复核':'失败' }}</text>
					</view>
				</div>
			</uni-td>
        </uni-tr>
    </uni-table>
    <view class="uni-pagination-box">
		<uni-pagination show-icon :page-size="pageSize" :current="currentPage"
        :total="total" @change="change" />
	</view>
  </view>
</template>

<script>
// 引入uni-ui组件
import {
  uniPagination,
  uniIcons,
  uniCard,
  uniTable,
  uniTr,
  uniTh,
  uniTd,
  uniEasyinput
} from "@dcloudio/uni-ui"
export default {
  data() {
    return {
      card_arr: [],//当前页码的表格数据
      pageSize: 15,// 每页数据量
      currentPage: 1,// 当前页
      total: 0,// 数据总量
      loading: false,
      selectedIndexs:[],//选中
	  
	  placeholderStyle:'font-size:17px;',
	  styles:{
	  	borderColor: '#999'
	  },
	  keyword:'',
	  where:' 1=1 ',
	  order_type:'',
	  FBillNoPda:'',//源单编码
	  user:uni.getStorageSync('user'),
	  
	  //在线版
	  config:uni.getStorageSync('myconfig'),
	  pageinfo:{},
	  //
    }
  },
  components: {
    uniPagination,
    uniIcons, //uni-ui的icons组件
    uniTable,
    uniTr,
    uniTh,
    uniTd,
	uniEasyinput
  },
  onPullDownRefresh() {
  	this.search()
  	uni.stopPullDownRefresh();
  },
  methods: {
	// 搜索
	search() {
		this.currentPage = 1
		this.getlist();
	},
	
    //获取列表
    getlist() {
		//20231204在线版
		this.pageinfo = {
			table:'fh',
			pagesize:this.pageSize,
			page:this.currentPage,
			order_str:'status asc',
			condition_str:JSON.stringify({
			  keyword:this.keyword,
			  warehouse_id:this.stock_id,
			  order_type:this.order_type,
			  uuid:uni.getStorageSync('uuid')
			})
		}
		
		uni.showLoading({mask:true})
		this.$Api.getPageList(this.pageinfo).then(res=>{
			if(res.data.code!=undefined&&res.data.code==0){
				this.$Api.msg(res.data.msg)
			}else{
				this.card_arr = res.data.data;
				this.total = res.data.total
				this.currentPage = res.data.current_page
			}
			uni.hideLoading();
		}).catch(err=>{
			this.$Api.msg(err)
		})
		//
    },
    change(e) {
      this.currentPage = e.current
      this.getlist()
    },
	// 多选
	selectionChange(e) {
		this.selectedIndexs = e.detail.index
	},
	//复核并同步
	toCheck(){
		//回传数据
		let _this = this;
		let pcode_arr = []
		
		// if(!this.selectedIndexs.length||this.selectedIndexs.length>1){
		// 	this.$Api.msg("请选择单条记录进行复核");
		// 	return 
		// }
		// let bill = this.card_arr[this.selectedIndexs[0]]
		
		uni.showModal({
		    title: '确定要复核并同步该记录?',
		    //content: '确定要删除记录？',
		    success: function (res) {
		        if (res.confirm) {
					if(_this.selectedIndexs.length>0){
						_this.selectedIndexs.forEach(key=>{
							let pcode = _this.card_arr[key].pcode
							if(pcode_arr.indexOf(pcode)=== -1){
							    pcode_arr.push(pcode)
							}
						})
						uni.showLoading();
						_this.$Api.toFh(pcode_arr,_this.user.userid,_this.order_type).then(res=>{
							uni.hideLoading();
							_this.$refs.table.clearSelection()
							
							if(res.data.code){
								_this.$Api.msg('操作成功','success')
								setTimeout(function() {
									_this.getlist()
								}, 800);
							}else{
								_this.$Api.msg(res.data.msg)
							}
						}).catch(err=>{
							uni.hideLoading();
							_this.$Api.msg(err)
						})
					}else{
						_this.$Api.msg('请选择要复核的记录')
					}
				}
			},
		})
	},
	selectes(item) {
	  // if (item == '') return
	  // uni.navigateTo({
	  // 	url:'/pages/stockbill/item?FBillNo='+item.FBillNo+'&order_type='+this.order_type,
	  // 		delta:1
	  // })
	},
  },
  mounted(e) {
  },
  onLoad(e) {
	this.order_type = e.type
	this.getlist()
	this.$Func.setBarTitle('复核列表')
  }
}
</script>
<style lang="less">
</style>